package com.ssy.lingxi.report.serviceimpl;

import cn.hutool.core.collection.CollectionUtil;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.api.feign.inner.MemberDetailFeign;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.request.MemberFeignUserIdVO;
import com.ssy.lingxi.message.api.feign.SystemMessageControllerFeign;
import com.ssy.lingxi.message.api.vo.request.SystemMessageRequest;
import com.ssy.lingxi.report.service.IFeignService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 内部接口实现
 * @author 伍将
 * @date 2020/12/22
 * @version 2.0.0
 */
@Service
public class FeignServiceImpl implements IFeignService {

    private static final Logger logger = LoggerFactory.getLogger(FeignServiceImpl.class);

    @Resource
    private SystemMessageControllerFeign systemMessageControllerFeign;
    @Resource
    private MemberDetailFeign memberDetailFeign;

    /**
     * 发送系统通知
     * @author 伍将
     * @date 2020/12/22
     * @param request:
     **/
    @Async
    @Override
    public void sendSystemMessage(SystemMessageRequest request) {
        try {
            systemMessageControllerFeign.sendSystemMessage(request);
        } catch (Exception e) {
            logger.info("调用报表服务新增系统通知接口失败：{}", e.getMessage());
        }
    }

    /**
     * 批量发送系统通知
     * @author 伍将
     * @date 2020/12/22
     * @param request:
     **/
    @Override
    public void batchSendSystemMessage(List<SystemMessageRequest> request) {
        try {
            systemMessageControllerFeign.batchSendSystemMessage(request);
        } catch (Exception e) {
            logger.info("调用报表服务批量新增系统通知接口失败：{}", e.getMessage());
        }
    }

    @Override
    public List<String> getWebLimitUrlListByUserId(Long userId) {
        MemberFeignUserIdVO vo=new MemberFeignUserIdVO();
        vo.setUserId(userId);
        Wrapper<List<String>> userWebAuthUrls = memberDetailFeign.getUserWebAuthUrls(vo);
        if(userWebAuthUrls!=null&& ResponseCode.SUCCESS.getCode()==userWebAuthUrls.getCode()){
            List<String> data = userWebAuthUrls.getData();
            if(CollectionUtil.isNotEmpty(data)){
                return data;
            }
        }
        return null;
    }

//    private List<String> testData(){
//        Map<String, String> map=new HashMap<>();
//        map.put("/memberCenter/afterService/returnApplication/returnPrSubmit","/memberCenter/afterService/returnApplication/returnPrSubmit");
//        map.put("/memberCenter/afterService/returnApplication/returnPrAddDeliver","/memberCenter/afterService/returnApplication/returnPrAddDeliver");
//        map.put("/memberCenter/afterService/returnApplication/returnPrAddLogistics","");
//        map.put("/memberCenter/afterService/returnManage/returnPr1","/memberCenter/afterService/returnManage/returnPr1");
//        map.put("/memberCenter/afterService/returnManage/returnPr2","/memberCenter/afterService/returnManage/returnPr2");
//        return new ArrayList<>(map.keySet());
//    }
}


